# Contributor: Natanael Copa <ncopa@alpinelinux.org>
# Maintainer:
pkgname=gutenprint
pkgver=5.2.11
pkgrel=0
pkgdesc="Printer Drivers Package"
url="http://gimp-print.sourceforge.net/"
arch="all"
license="GPL-2.0-or-later"
depends=""
depends_dev=""
makedepends="$depends_dev cups-dev tiff-dev libjpeg-turbo-dev libpng-dev
	ghostscript-dev libusb-dev autoconf automake libtool gettext-dev"
install=""
subpackages="$pkgname-dev $pkgname-doc $pkgname-lang $pkgname-libs
	$pkgname-cups $pkgname-samples"
source="https://downloads.sourceforge.net/gimp-print/gutenprint-$pkgver.tar.bz2
	musl-fix-header.patch
	pagesize-name-clash.patch
	gutenprint-O6.patch
	"

_builddir="$srcdir"/gutenprint-$pkgver
prepare() {
	local i
	cd "$_builddir"
	for i in $source; do
		case $i in
		*.patch) msg $i; patch -p1 -i "$srcdir"/$i || return 1;;
		esac
	done
	mkdir -p m4local
	autoreconf -vif || return 1
}

build() {
	cd "$_builddir"
	./configure \
		--build=$CBUILD \
		--host=$CHOST \
		--prefix=/usr \
		--sysconfdir=/etc \
		--mandir=/usr/share/man \
		--infodir=/usr/share/info \
		--localstatedir=/var \
		--disable-nls \
		--disable-cups-ppds \
		--enable-simplified-cups-ppds \
		|| return 1
	make || return 1
}

package() {
	cd "$_builddir"
	make DESTDIR="$pkgdir" install || return 1
	rm -r "$pkgdir"/usr/share/gutenprint/doc \
		"$pkgdir"/etc/cups/command.types \
		|| return 1
}

cups() {
	pkgdesc="CUPS drivers for Canon, Epson, HP and compatible printers"
	for d in usr/share usr/lib usr/bin usr/sbin etc; do
		mkdir -p "$subpkgdir"/$d || return 1
		mv "$pkgdir"/$d/cups* "$subpkgdir"/$d/ || return 1
	done
}

samples() {
	pkgdesc="Sample test pattern generator for gutenprint-dev"
	mkdir -p "$subpkgdir"/usr/share/gutenprint "$subpkgdir"/usr/bin
	mv "$pkgdir"/usr/share/gutenprint/samples \
		"$subpkgdir"/usr/share/gutenprint/ || return 1
	mv "$pkgdir"/usr/bin/testpattern "$subpkgdir"/usr/bin/ || return 1

}

sha512sums="f4010e489dd6763b19113abf1d55e84cea8d36b920d03dbe204dba30ab0d3fb3e3391e739cd1a56e2f63581c8ce4a856a7f747deb6e7b18d7e1f7a3d87901c60  gutenprint-5.2.11.tar.bz2
97c38aa2d7931af25e577e27949f659bd45be3e9deab0af86e437587a526d5d37006d0fddd57ad22e1bbe39f25dfa34926e75690a243c7736840cf85ca5ae2df  musl-fix-header.patch
8b17b4d3dd3f9dbeff7c3a3da38395cde8bea51abe5a8ebeac62b9e442dc451341b3571de02437d035a63da83d10316a4ce0da143cc90a935678a01fb5efb224  pagesize-name-clash.patch
81cdbd3ff271fec2d7d17313772db6d2617da90bd532a6e2d834e8bfde9e5329a62b01876714be145dbf23071a053374b1b78dd173ea999d0e873b895b49d0a6  gutenprint-O6.patch"
